package controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import util.MySessionContext;

@CrossOrigin(originPatterns="*",allowCredentials="true",maxAge = 3600)
@Controller
public class Test2 {
	@RequestMapping("/test2")
	@ResponseBody
	public String register2(HttpServletRequest request,HttpServletResponse response,
		@RequestParam("sid") String sid	) {
		 HttpSession session = request.getSession();
		 System.out.println(session.getId());
		 System.out.println(session.getAttribute("loginUserName"));
		
		
		
		
//		//System.out.println(request.getSession().getAttribute("loginUserName").toString());
//		System.out.println(request.getSession().getId());
//		System.out.println(sid);
//		MySessionContext myc= MySessionContext.getInstance();  
////		HttpSession session = request.getSession().getSessionContext().getSession(sid); 这个方法已经被废弃
//		HttpSession session = myc.getSession(sid);  //此处就是通过sessionId获取session信息
//		if(session!=null) {
//			String user=String.valueOf(session.getAttribute("loginUserName"));
//			//String keySecret=String.valueOf(session.getAttribute("keySecret"));
//			//map.put("user", user);
//			//map.put("keySecret", keySecret);
//			System.out.println(session.getId());
//			System.out.println(user);
//		}
//		System.out.println(session);
		return "2";
	}
}
